<?php

namespace admin\controllers;

use app\models\Comment;
use admin\components\AdminController;

class CommentController extends AdminController {

    public $name = '评论管理';

    public function actionIndex() {

        $own = $this->get('own', Comment::OWN_ACTIVITY);

        $searchModel = !$this->enableSearch ? NULL : new Comment();
        $query = Comment::find();
        $query->andWhere(['own' => $own]);
        $query->with(['user']);

        $dataProvider = $this->search($query, $searchModel);
        return $this->render(compact('searchModel', 'dataProvider', 'status'));
    }
    
    public function actionAction($id) {
        /* @var $model Comment */
        $model = $this->findModel($id);
        if (!$model) {
            return $this->error('');
        }
        $model->status = $model->getIsDeny() ? Comment::STATUS_YES : Comment::STATUS_NO;
        return $model->save();
    }
}
